/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.fzhucc.modules.sciEnterprise.controller;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.modules.sciEnterprise.domain.SciEnterprise;
import com.fzhucc.modules.sciEnterprise.domain.dto.*;
import com.fzhucc.modules.sciEnterprise.service.SciEnterpriseService;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.AllowSciPersonnelInfoDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.AuditSciPersonnelInfoDto;
import com.fzhucc.modules.sciPersonnelInfo.domain.dto.SciPersonnelInfoDto;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
 * @author yyg
 * @date 2024-06-03
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "劳模需求企业:管理")
@RequestMapping("/api/sciEnterprise")
public class SciEnterpriseController {

    private final SciEnterpriseService sciEnterpriseService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('sciEnterprise:list')")
    public void exportSciEnterprise(HttpServletResponse response, SciEnterpriseQueryCriteria criteria) throws IOException {
        sciEnterpriseService.download(sciEnterpriseService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询劳模需求企业")
    @ApiOperation("查询劳模需求企业")
    @PreAuthorize("@el.check('sciEnterprise:list')")
    public ResponseEntity<Object> querySciEnterprise(SciEnterpriseQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciEnterpriseService.queryAll(criteria,pageable), HttpStatus.OK);
    }

    @PostMapping
    @Log("新增劳模需求企业")
    @ApiOperation("新增劳模需求企业")
    //@PreAuthorize("@el.check('sciEnterprise:add')")
    public ResponseEntity<Object> createSciEnterprise(@Validated @RequestBody SciEnterpriseAddDto dto){
        return new ResponseEntity<>(sciEnterpriseService.create(dto), HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改劳模需求企业")
    @ApiOperation("修改劳模需求企业")
    //@PreAuthorize("@el.check('sciEnterprise:edit')")
    public ResponseEntity<Object> updateSciEnterprise(@Validated @RequestBody SciEnterpriseEditDto dto){
        sciEnterpriseService.update(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除劳模需求企业")
    @ApiOperation("删除劳模需求企业")
    @PreAuthorize("@el.check('sciEnterprise:del')")
    public ResponseEntity<Object> deleteSciEnterprise(@RequestBody Integer[] ids) {
        sciEnterpriseService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping("/{id}")
    @Log("查询单个劳模需求企业")
    @ApiOperation("查询单个劳模需求企业")
    public SciEnterpriseDto queryInfoById(@PathVariable Integer id) {
        return sciEnterpriseService.findById(id);
    }

    /*@AnonymousAccess
    @GetMapping(value = "/queryPassEntertprise")
    @Log("h5查询审核通过的企业列表")
    @ApiOperation("h5查询审核通过的企业列表")
    public ResponseEntity<Object> queryPassEntertprise() {
        return new ResponseEntity<>(sciEnterpriseService.queryPassEntertprise(), HttpStatus.OK);
    }

    @AnonymousAccess
    @GetMapping(value = "/queryPassEntertpriseByNo")
    @Log("h5查询审核通过的企业列表分页")
    @ApiOperation("h5查询审核通过的企业列表分页")
    public ResponseEntity<Object> queryPassEntertpriseByNo(SciEnterpriseQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(sciEnterpriseService.queryPassEntertpriseByNo(criteria,pageable), HttpStatus.OK);
    }*/

    @AnonymousAccess
    @GetMapping(value = "/queryPassEntertpriseByName")
    @Log("h5查询审核通过的企业列表By名字模糊查询")
    @ApiOperation("h5查询审核通过的企业列表By名字模糊查询")
    public ResponseEntity<Object> queryPassEntertpriseByName(SciEnterpriseNameQueryCriteria criteria) {
        return new ResponseEntity<>(sciEnterpriseService.queryPassEntertpriseByName(criteria), HttpStatus.OK);
    }

    @GetMapping(value = "/getQyAuditStatus")
    @Log("获取字典qy_audit_status企业审核状态")
    @ApiOperation("获取字典qy_audit_status企业审核状态")
    @AnonymousAccess
    public ResponseEntity<Object> getQyAuditStatus() {
        return new ResponseEntity<>(sciEnterpriseService.getQyAuditStatus(), HttpStatus.OK);
    }

    @GetMapping(value = "/getCraftsmanEnterpriseProperty")
    @Log("获取字典craftsman_enterprise_property企业性质")
    @ApiOperation("获取字典craftsman_enterprise_property企业性质")
    @AnonymousAccess
    public ResponseEntity<Object> getCraftsmanEnterpriseProperty() {
        return new ResponseEntity<>(sciEnterpriseService.getCraftsmanEnterpriseProperty(), HttpStatus.OK);
    }

    @PutMapping(value = "/audit")
    @Log("劳模需求企业状态审核")
    @ApiOperation("劳模需求企业状态审核")
    public ResponseEntity<Object> auditQy(@Validated @RequestBody AuditEnterpriseDto dto) {
        sciEnterpriseService.auditQy(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PutMapping(value = "/isAllowEdit")
    @Log("是否允许编辑")
    @ApiOperation("是否允许编辑")
    public ResponseEntity<Object> isAllowEdit(@Validated @RequestBody AllowEnterpriseDto dto) {
        sciEnterpriseService.isAllowEdit(dto);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
}